//后台工厂图片路由
const express = require('express');
const path = require("path");
const multer = require('multer');
/* const moment = require("moment")
const factoryPicModel = require("../models/factoryPic.js"); */
const factoryPicController = require("../controllers/factoryPicController.js")
const router = express.Router();
//上传图片
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname, '../public/uploads'))
    },
    filename: function (req, file, cb) {
        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9)
        cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname))
    }
})
const upload = multer({ storage: storage });
//工厂照片表单显示
router.get("/factoryPic/add", factoryPicController.showAddPicForm)
//数据库操作
router.post("/factoryPic/Store", upload.single("src"), factoryPicController.addPic);
//工厂照片列表显示
router.get("/factoryPic/list", factoryPicController.getPicList);
//工厂照片删除操作
router.get('/factoryPic/del/:id', factoryPicController.delPic);
//工厂照片编辑表单显示
router.get("/factoryPic/edit/:id", factoryPicController.showPicEditForm);
//工厂照片编辑表单数据库操作
router.post("/factoryPic/editStore", upload.single("src"), factoryPicController.editPic);
module.exports = router